/**
 * @program: yygh_parent
 * @ClassName AdminHospitalController
 * @description:
 * @author: zyw
 * @create: 2023-05-25 15:27
 * @Version 1.0
 **/
package com.atguigu.yygh.hosp.controller.admin;

import com.atguigu.yygh.common.result.R;
import com.atguigu.yygh.hosp.service.HospitalService;
import com.atguigu.yygh.model.hosp.Hospital;
import com.atguigu.yygh.vo.hosp.HospitalQueryVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/hospital")
public class AdminHospitalController {

    @Autowired
    private HospitalService hospitalService;

    @ApiOperation("获取分页列表")
    @GetMapping("/{pageNum}/{pageSize}")
    public R getHospitalPage(
            @PathVariable Integer pageNum
            , @PathVariable Integer pageSize
            , HospitalQueryVo hospitalQueryVo) {
        Page<Hospital> hospitalPage =
                hospitalService.getHospitalPage(pageNum, pageSize, hospitalQueryVo);
        System.out.println("hospitalPage = " + hospitalPage);
        List<Hospital> content = hospitalPage.getContent();
        for (Hospital hospital : content) {
            System.out.println("hospital.getHosname() = " + hospital.getHosname());
        }
        return R.ok().
                data("total", hospitalPage.getTotalElements()).
                data("list", hospitalPage.getContent());
    }

    @GetMapping("/updateStatus/{id}/{status}")
    @ApiOperation(value = "更改上线下线状态")
    public R updateStatus(@PathVariable(value = "id") String id,
                          @PathVariable(value = "status") Integer status) {
        hospitalService.updateStatus(id, status);
        return R.ok();
    }

    @GetMapping("/datail/{id}")
    public R detail(@PathVariable(value = "id") String id) {
        Hospital hospital = hospitalService.detail(id);
        return R.ok().data("hospital",hospital);
    }
}
 
